package com.frame.auth.resource.security.handler;

import com.frame.common.core.util.ResponseUtils;
import com.frame.common.tools.result.ResultCode;
import com.frame.common.tools.result.ServiceResult;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 如果身份验证失败时调用
 *
 * @auther zhangwj
 * @date 2021/3/18 下午1:47
 */
public class GoAuthenticationFailureHandler implements AuthenticationFailureHandler {

    @Override
    public void onAuthenticationFailure(HttpServletRequest httpServletRequest,
                                        HttpServletResponse httpServletResponse,
                                        AuthenticationException e) throws IOException, ServletException {
        ResponseUtils.writeJson(httpServletResponse, ServiceResult.getFailureResult(ResultCode.VALIDATION_FAILED));
    }
}
